package org.japo.java.basics.entities;

public class Color {

    private int r;
    private int v;
    private int a;

    public Color() {
    }

    public Color(int r, int v, int a) {
        if (validarColor(r, v, a)) {
            this.r = r;
            this.v = v;
            this.a = a;
        }
    }

    public int getR() {
        return r;
    }

    public void setR(int r) {
        if (validarColor(r, v, a)) {
            this.r = r;
        }
    }

    public int getV() {
        return v;
    }

    public void setV(int v) {
        if (validarColor(r, v, a)) {
            this.v = v;
        }

    }

    public int getA() {
        return a;
    }

    public void setA(int a) {
        if (validarColor(r, v, a)) {
            this.a = a;
        }

    }

    private boolean validarColor(int r, int v, int a) {
        return r >= 0 && r <= 255
                && v >= 0 && v <= 255
                && a >= 0 && a <= 255;
    }

    @Override
    public String toString() {
        String cR = "0" + Integer.toHexString(this.r);
        cR = cR.substring(cR.length() - 2);
        String cV = "0" + Integer.toHexString(this.v);
        cV = cV.substring(cV.length() - 2);
        String cA = "0" + Integer.toHexString(this.a);
        cA = cA.substring(cA.length() - 2);
        return String.format("#%s%s%s", r, v, a);
    }

    public void mostrarColor() {
        System.out.println(toString());
    }

}
